﻿function validateOnlyNo(id) { $(id).blur(function () { $(id).val($(id).val().replace(/[^0-9\/"."]+/g, '')); }); $(id).val($(id).val().replace(/[^0-9\/]+/g, '')); }
function validateNoWithDot(id) { $(id).blur(function () { $(id).val($(id).val().replace(/[^0-9\/"."]+/g, '')); }); $(id).val($(id).val().replace(/[^0-9\/"."]+/g, '')); }
function replaceCharacter(value) { var filterTextBox = value.replace(/'/g, "`"); return filterTextBox; }
function ValidateDates(parm1, parm2, date1obj, date2obj, secondDateMandatory) {
    var firstDate = $.trim($("#" + date1obj).val()); var secondDate = $.trim($("#" + date2obj).val()); var fitstDateRange = firstDate.substring(firstDate.lastIndexOf('/') + 1); var secondDateRange = secondDate.substring(secondDate.lastIndexOf('/') + 1); if (firstDate == "") { alert("Please enter " + parm1); $("#" + date1obj).focus(); return false; }
    else if (validateDateFormat(date1obj)) {
        if (secondDate != "") {
            if (validateDateFormat(date2obj)) {
                if (parseInt(fitstDateRange) < 1900) { alert(parm1 + " should be between 01/01/1900 and 12/31/2070"); $("#" + date1obj).val(""); $("#" + date1obj).focus(); return false; }
                else if (parseInt(secondDateRange) > 2070) { alert(parm2 + " should be between 01/01/1900 and 12/31/2070"); $("#" + date2obj).val(""); $("#" + date2obj).focus(); return false; }
                else if (Date.parse(firstDate) > Date.parse(secondDate)) { alert(parm1 + " can not be greater than " + parm2); $("#" + date1obj).val(""); $("#" + date1obj).focus(); return false; }
            }
            else { return false; }
        }
        else if (secondDateMandatory) { alert("Please enter " + parm2); $("#" + date2obj).focus(); return false; }
    }
    else { return false; }
    return true;
}
function validateDateFormat(dateObj) {
    var validformat = /^\d{2}\/\d{2}\/\d{4}$/; var datevalue = $.trim($("#" + dateObj).val()); if (datevalue != "" && datevalue != "__/__/____") {
        var returnval = false; if (!validformat.test(datevalue)) { alert("Invalid Date Format. Please correct and submit again"); $("#" + dateObj).val(""); $("#" + dateObj).focus(); return false; }
        else { var monthfield = datevalue.split("/")[0]; var dayfield = datevalue.split("/")[1]; var yearfield = datevalue.split("/")[2]; var dayobj = new Date(yearfield, monthfield - 1, dayfield); if ((dayobj.getMonth() + 1 != monthfield) || (dayobj.getDate() != dayfield) || (dayobj.getFullYear() != yearfield)) { alert("Invalid Day, Month, or Year range detected. Please correct and submit again"); $("#" + dateObj).val(""); $("#" + dateObj).focus(); return false; } }
    }
    return true;
}
function addDaysInCurrentDate(daysToAdd, Parm) {
    var currentDate = new Date(); if (Parm == "-")
        currentDate.setDate(currentDate.getDate() - daysToAdd); else
        currentDate.setDate(currentDate.getDate() + daysToAdd); var vFormat = "MM/dd/yyyy"; var vDay = addZero(currentDate.getDate()); var vMonth = addZero(currentDate.getMonth() + 1); var vYearLong = addZero(currentDate.getFullYear()); var vYearShort = addZero(currentDate.getFullYear().toString().substring(3, 4)); var vYear = (vFormat.indexOf("yyyy") > -1 ? vYearLong : vYearShort)
    var vHour = addZero(currentDate.getHours()); var vMinute = addZero(currentDate.getMinutes()); var vSecond = addZero(currentDate.getSeconds()); var CurrentDateString = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear); return CurrentDateString;
}
function addZero(vNumber) { return ((vNumber < 10) ? "0" : "") + vNumber; }
function replaceSingleQuotes(value) { var filterTextBox = value.replace(/`/g, "'"); return filterTextBox; }
function replaceSpace(value) { var filterTextBox = value.replace(" ", ""); return filterTextBox; }
function replaceDoubleQuotes(value) { var filterTextBox = value.split("\"").join(""); return filterTextBox; }
function isValidEmailAddress(emailAddress) { var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i); return pattern.test(emailAddress); }
function convertDatetoString(dateStr, isAM) {
    if (dateStr == "" || dateStr == null || dateStr == "null")
        return ""; var m, day; jsonDate = dateStr; var d = new Date(parseInt(jsonDate.substr(6))); m = d.getMonth() + 1; if (m < 10)
        m = '0' + m
    if (d.getDate() < 10)
        day = '0' + d.getDate()
    else
        day = d.getDate(); if (isAM == 'true')
        return (m + '/' + day + '/' + d.getFullYear() + ' ' + d.toLocaleTimeString())
    if (isAM == 'false')
        return (m + '/' + day + '/' + d.getFullYear() + ' ' + d.toTimeString().substr(0, 9))
    if (isAM == 2)
        return (m + '/' + day + '/' + d.getFullYear())
}
function GenerateSimpleSerialNumber(tableName, rowNumber, columnNumber) {
    var i = 0; $("#" + tableName + " tr").each(function () {
        if (i >= (rowNumber - 1)) { $(this).children('td').eq((columnNumber - 1)).html((i - (rowNumber - 2)).toString()); }
        i++;
    });
}
$.fn.row = function (i) { return $('tr:nth-child(' + (i + 1) + ') td', this); }
$.fn.column = function (i) { return $('tr td:nth-child(' + (i + 1) + ')', this); }
function MergeCells(tableName, colNum) {
    var tds = new Array(); var mainList = new Array(); var subList = new Array(); tds = $(tableName).column(colNum); for (var i = 0; i < tds.length; i++) {
        if (i != tds.length - 1) {
            if ($(tds[i]).html().trim() == $(tds[i + 1]).html().trim()) { subList.push(tds[i]); }
            else { subList.push(tds[i]); mainList.push(subList); subList = new Array(); }
        }
        else { subList.push(tds[i]); mainList.push(subList); subList = new Array(); }
    }
    for (var i = 0; i < mainList.length; i++) {
        var tempList = mainList[i]; var value = $(tempList[0]).html().trim(); var firstTd = tempList[0]; if (tempList.length > 1) {
            for (var j = 1; j < tempList.length; j++) { $(tempList[j]).remove(); }
            $(firstTd).attr("rowspan", tempList.length.toString());
        }
    }
}
function GenerateSrNumberWithWhiteRow(tableName, rowNumber, columnNumber) {
    $("#" + tableName + " tr").removeClass("odd even"); $("#" + tableName + " tr:gt(" + (rowNumber - 1) + ")").each(function (i) {
        if (i % 2 == 0) { $(this).addClass("odd"); }
        else { $(this).addClass("even"); }
    });
}
function GenerateAlternateRowColor(tableName, rowNumber, columnNumber) {
    $("#" + tableName + " tr").removeClass("odd even"); $("#" + tableName + " tr:gt(" + (rowNumber - 1) + ")").each(function (i) {
        if (i % 2 == 0) { $(this).addClass("odd"); }
        else { $(this).addClass("even"); }
    });
}
function setCursorPosition(pos, obj) {
    $(obj).focus(); if ($(obj).get(0).setSelectionRange) { $(obj).get(0).setSelectionRange(pos, pos); }
    else if ($(obj).get(0).createTextRange) { var range = $(obj).get(0).createTextRange(); range.collapse(true); range.moveEnd('character', pos); range.moveStart('character', pos); range.select(); }
}
function keyRestrict1(e, validchars, casesensitives, onceevery, onceoneof) {
    validchars += '\\"'; onceevery = onceevery ? onceevery : ""; onceoneof = onceoneof ? onceoneof : ""; if (!validchars)
        return true; var key = '', keychar = '', obj = '', i = 0; var ua = $.browser; var key; if (ua.msie) { key = e.which ? e.which : window.event.keyCode; }
    else { key = e.which ? e.which : e.keyCode; }
    var obj = e.target ? e.target : window.event.srcElement; if (key == null)
        return true; keychar = String.fromCharCode(key); validchars = (validchars + onceevery + onceoneof); if (!casesensitives) { keychar = keychar.toLowerCase(); validchars = validchars.toLowerCase(); onceevery = onceevery.toLowerCase(); onceoneof = onceoneof.toLowerCase(); }
    for (i = 0; i < (onceevery + onceoneof).length; i++) {
        if (i < onceevery.length) {
            if (obj.value.indexOf(onceevery.charAt(i)) != -1 && keychar == onceevery.charAt(i))
                return false;
        }
        else {
            if (obj.value.indexOf(onceoneof.charAt(i - onceevery.length)) != -1 && onceoneof.indexOf(keychar) != -1)
                return false;
        }
    }
    if (validchars.indexOf(keychar) != -1)
        return true; if (key == null || key == 0 || key == 8 || key == 9 || key == 27 || key == 13 || key == 37 || key == 38 || key == 39 || key == 40)
        return true; return false;
}
/*Added By Waqas call this method and pass only those charecters which you want to Restrict*/
function RestricKey2(e, Invalidchars) {
    var key = '', keychar = '';
    var ua = $.browser;
    if (ua.msie) {
        key = e.which ? e.which : window.event.keyCode;
    }
    else {
        key = e.which ? e.which : e.keyCode;
    }

    if (key == null)
        return true;
    keychar = String.fromCharCode(key);
    keychar = keychar.toLowerCase();
    Invalidchars = Invalidchars.toLowerCase();
    if (Invalidchars.indexOf(keychar) != -1)
        return false;
    else
        return true;
}
function checkMaxLen(id, maxLen) { var input = $(id).val(); if ($(id).val().length > maxLen) { input = input.substr(0, maxLen); $(id).val(input); return false; } }
function FillUserSettings(data) { if (data.length > 0) { for (var i = 0; i < data.length; i++) { var settings = new ConfigSettings(); settings.Description = data[i].Description; settings.Option = data[i].Options; settings.Control_Type = data[i].CONTROL_TYPE; settings.Module_Name = data[i].MODULE_NAME; settings.Sub_Group_Name = data[i].Sub_Group_Name; settings.Display_Name = data[i].Display_Name; settings.Group_Sequence = data[i].Group_Sequence; settings.Show_User = data[i].SHOW_USERS; UserConfigSettings.Add(settings); } } }
function ConfigSettings() { this.Description = ''; this.Option = ''; this.Control_Type = ''; this.Module_Name = ''; this.Sub_Group_Name = ''; this.Display_Name = ''; this.Group_Sequence = ''; this.Show_User = ''; this.Message_Text = ''; this.ToolTip_Text = ''; }
var UserConfigSettings = { _userSettings: new Array(), Add: function (obj) {
    if (!this.IsExist(obj))
        this._userSettings.push(obj);
}, IsExist: function (Description) {
    for (i = 0; i < this._userSettings.length; i++) {
        if (Description == this._userSettings[i].Description)
            return true;
    }
    return false;
}, Find: function (Description) {
    for (i = 0; i < this._userSettings.length; i++) {
        if (Description == this._userSettings[i].Description)
            return this._userSettings[i];
    }
    return false;
}
}

/*Added By Waqas call this method to apply calender with specific input field*/
function applyDateCalender(inputId) {
    $('#' + inputId).datepicker({
        changeMonth: true,
        changeYear: true,
        showOn: "button",
        yearRange: "1950:+10"
    });
}

/*Added by Waqas to show Error Message  Div with  Error Message text*/
function showErrorDiv(obj, txt) {

    var objOffset = $("#" + obj).offset();
    //var objWidth = $("#" + obj).outerWidth();

    $("#ErrorMsg").html("<span class='requiredfield'>  *  &nbsp;&nbsp;</span>" + txt).css({
        position: "absolute",
        top: objOffset.top - 50 + "px",
        left: (objOffset.left) + "px"
    }).show();
    $("#" + obj).focus();
    setTimeout("HideErrorDiv()", 3000);
}
function HideErrorDiv() {
    $("#ErrorMsg").hide();
}
/**/
function hidePopUp() {
    $("#divmodelPop").jqmHide();
}
